<?php
/**
 * <https://y.st./>
 * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org./licenses/>.
**/

$xhtml = array(
	'title' => 'firstsubroutines.java',
	'subtitle' => 'Written in <span title="Programming 1">CS 1102</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalised on 2017-05-03',
	'copyright year' => '2017',
	'body' => <<<END
<h2>Source code:</h2>
<blockquote>
<pre><code>/*
 * Copyright (C) 2017 Alex Yst
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
package firstsubroutines;
import java.util.Scanner;

/**
 * Alex Yst&apos;s CS 1102 (Programming 1) Unit 4 submission
 * 
 * This class was programmed to fill the requirements on the Unit 4 programming
 * assignment in University of the People&apos;s CS 1102 (Programming 1) course.
 * 
 * @author Alex Yst
 */
public class firstsubroutines {
/**
 * This method reverses the string passed to it as an argument, and thus the
 * name of this method.
 * 
 * @param str The string to reverse
 * @return The reversed string
 */
	public static String reverse(String str) {
		String reverse = &quot;&quot;;
		for (int i = str.length() - 1; i &gt;= 0; i--) {
			reverse = reverse + str.charAt(i);
		}
		return reverse;
	}
/**
 * This method removes all non-letters and converts all letters to lower case.
 * 
 * In computer science, the conversion of strings to a unified for like this,
 * in which all equivilant strings are converted to an identical form, is
 * called normalization, and thus the name of this method.
 * 
 * @param str A string to be normalized
 * @return The normalized string
 */
	public static String normalize(String str) {
		str = str.toLowerCase();
		int end = str.length() -1;
		String normalized = &quot;&quot;;
		for (int i = 0; i &lt;= end; i++) {
			char ch = str.charAt(i);
			if(ch &gt;= &apos;a&apos; &amp;&amp; ch &lt;= &apos;z&apos;) {
				normalized = normalized + ch;
			}
		}
		return normalized;
	}
/**
 * This is just the main method. In Java, the main() method is called. Code
 * isn&apos;t simply included outside all method definitions when it needs to be
 * run.
 * 
 * @param arguments This parameter is unused.
 */
	public static void main(String[] arguments) {
		Boolean loop = true;
		Scanner scanner = new Scanner(System.in);
		String forward;
		String reverse;
		String compare;
		System.out.println(&quot;Please enter a string to be checked, or enter an empty string to abort:&quot;);
		String input = scanner.nextLine();
		while(!input.equals(&quot;&quot;)) {
			forward = normalize(input);
			reverse = reverse(forward);
			System.out.println(&quot;stripped: &quot;+forward);
			System.out.println(&quot;reversed: &quot;+reverse);
			if(forward.equals(reverse)) {
				compare = &quot;IS&quot;;
			} else {
				compare = &quot;is NOT&quot;;
			}
			System.out.println(&quot;This &quot;+compare+&quot; a palindrome.&quot;);
			System.out.println(&quot;Please enter a string to be checked, or enter an empty string to abort:&quot;);
			input = scanner.nextLine();
		}
	}
}</code></pre>
</blockquote>
<h2>Output:</h2>
<blockquote>
<pre>run:
Please enter a string to be checked, or enter an empty string to abort:
Hello World!
stripped: helloworld
reversed: dlrowolleh
This is NOT a palindrome.

Please enter a string to be checked, or enter an empty string to abort:
Campus motto: Bottoms up, Mac!
stripped: campusmottobottomsupmac
reversed: campusmottobottomsupmac
This IS a palindrome.

Please enter a string to be checked, or enter an empty string to abort:

BUILD SUCCESSFUL (total time: 21 seconds)</pre>
</blockquote>
END
);
